package org.example.userservice.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.mapper.CartMapper;
import org.example.mapper.CustomerMapper;
import org.example.mapper.GoodsMapper;
import org.example.pojo.userdto.CustomerLoginDTO;
import org.example.pojo.userdto.CustomerLookDTO;
import org.example.pojo.entity.Goods;
import org.example.pojo.PageBean;
import org.example.userservice.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.example.pojo.entity.Customer;

import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private CartMapper cartMapper;

    @Override
    public void insert(Customer customer) {
        customerMapper.insertCustomer(customer);
    }

    @Override
    public Customer select(CustomerLoginDTO customerLoginDTO) {
        return customerMapper.getCustomer(customerLoginDTO);
    }

    @Override
    public void delete(Long id) {
        customerMapper.delete(id);
    }

    @Override
    public PageBean lookthrough(CustomerLookDTO customerLookDTO) {
        Integer page=customerLookDTO.getPage(),pageSize=customerLookDTO.getPageSize();
        PageHelper.startPage(page, pageSize);
        List<Goods> goods = goodsMapper.list(customerLookDTO.getName(),
                customerLookDTO.getPrice1(),customerLookDTO.getPrice2());
        Page<Goods> goodsPage = (Page<Goods>) goods;
        PageBean p = new PageBean(goodsPage.getTotal(),goodsPage.getResult());
        return p;
    }


}
